# -*- coding: utf-8 -*-
import time
import json

from amac_spider.items import CancelledManagerItem
from amac_spider.utils.my_redis_spider import RedisSpiderPro
from amac_spider.utils.handler import get_date, get_datetime


# 已注销私募基金管理人名单
class CancelledManagerSpider(RedisSpiderPro):
    name = 'cancelled_manager'

    def parse(self, response):
        item = CancelledManagerItem()
        type_mappings = {'100': '主动注销', '200': '依公告注销', '300': '协会注销'}
        mappings = {'manager': 'orgName', 'code': 'orgCode', 'register_time': 'orgSignDate',
                    'cancel_time': 'cancelDate', 'cancel_type': 'status', 'user_tenant_id': 'userTenantId'}
        info_list = json.loads(response.text)['content']
        for info in info_list:
            for k, v in mappings.items():
                item[k] = info[v]
            item['register_time'] = get_date(item['register_time']/1000)
            item['cancel_time'] = get_date(item['cancel_time']/1000)
            item['cancel_type'] = type_mappings[str(item['cancel_type'])]
            item['crawl_time'] = get_datetime(time.time())
            yield item



